package com.youdoneed.community.forum.web;

import com.youdoneed.base.common.JWTUtils;
import com.youdoneed.community.common.vo.ResultMessage;
import com.youdoneed.community.forum.service.MsgViewRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by lid on 2017/11/7 0007.
 * 3D视频、酷视频浏览记录控制器
 */
@RestController
@RequestMapping(value = "/msgViewRecord", method = {RequestMethod.GET, RequestMethod.POST})
@Api(value = "保存3D视频、酷视频浏览记录", description = "保存3D视频、酷视频浏览记录")
public class MsgViewRecordController {

    private static final Logger logger = LoggerFactory.getLogger(MsgViewRecordController.class);

    @Autowired
    MsgViewRecordService msgViewRecordService;

    @RequestMapping(value = "/saveViewRecord", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "保存3D视频、酷视频浏览记录", value = "保存3D视频、酷视频浏览记录")
    public ResultMessage<?> saveViewRecord(@ApiParam(value = "客户端请求头附带参数") @RequestHeader(value = "Authorization") String token,
                                           String msgId, String msgType) {
        String userId = JWTUtils.getTokenUserId(token);
        if (StringUtils.hasText(userId)) {
            logger.info("userId:" + userId);
        }

        msgViewRecordService.saveRecord(msgId, userId, msgType);
        return ResultMessage.newSuccess("保存浏览记录成功!");
    }

}
